home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / FROMUTS / DDEPASCAL / DDE / !PC / h / flex < prev    next >
Text File  |  1992-02-10  |  5KB  |  139 lines

  1. (*
  2.  * Title  : flex.h
  3.  * Purpose: provide memory allocation for interactive programs requiring
  4.  *          large chunks of store. Such programs must respond to memory
  5.  *          full errors.
  6.  *
  7.  *)
  8.  
  9. #ifndef __flex_h
  10. #define __flex_h
  11.  
  12. type flex_ptr = ^pointer;
  13.  
  14.  
  15. (* ----------------------------- flex_alloc -------------------------------
  16.  * Description:   Allocates n bytes of store, obtained from the Wimp.
  17.  *
  18.  * Parameters:    flex_ptr anchor -- to be used to access allocated store
  19.  *                int n -- number of bytes to be allocated
  20.  * Returns:       0 == failure, 1 == success
  21.  * Other Info:    You should pass  a pointer variable as the first
  22.  *                parameter. The allocated store MUST then be accessed
  23.  *                through this.
  24.  *                This is important since  the allocated store may later be
  25.  *                moved (it's a shifting heap!!). If there's not enough
  26.  *                store returns zero leaving anchor unchanged.
  27.  *
  28.  *)
  29. function flex_alloc(anchor : flex_ptr; n : integer) : boolean; extern;
  30.  
  31.  
  32. (* ------------------------------ flex_free -------------------------------
  33.  * Description:   Frees the previously allocated store.
  34.  *
  35.  * Parameters:    flex_ptr anchor -- pointer to allocated store
  36.  * Returns:       void.
  37.  * Other Info:    *anchor will be set to 0.
  38.  *
  39.  *)
  40. procedure flex_free(anchor : flex_ptr); extern;
  41.  
  42.  
  43. (* ------------------------------- flex_size ------------------------------
  44.  * Description:   Informs caller of the number of bytes allocated
  45.  *
  46.  * Parameters:    flex_ptr -- pointer to allocated store
  47.  * Returns:       number of allocated bytes. 
  48.  * Other Info:    None.
  49.  *
  50.  *)
  51. function flex_size(anchor : flex_ptr) : integer; extern;
  52.  
  53.  
  54. (* --------------------------- flex_extend --------------------------------
  55.  * Description:   Extend ot truncate the store area to have a new size.
  56.  *
  57.  * Parameters:    flex_ptr -- pointer to allocated store
  58.  *                int newsize -- new size of store
  59.  * Returns:       0 == failure, 1 == success.
  60.  * Other Info:    None.
  61.  *
  62.  *)
  63. function flex_extend(anchor : flex_ptr;
  64.                 newsize : integer) : integer; extern;
  65.  
  66.  
  67. (* --------------------------- flex_midextend -----------------------------
  68.  * Description:   Extend or truncate store, at any point.
  69.  *
  70.  * Parameters:    flex_ptr -- pointer to allocated store
  71.  *                int at -- location within the allocated store
  72.  *                int by -- extent
  73.  * Returns:       0 == failure, 1 == success
  74.  * Other Info:    If by is +ve, then store is extended, and locations above
  75.  *                "at" are copied up by "by".
  76.  *                If by is -ve, then store is reduced, and any bytes beyond
  77.  *                "at" are copied down to "at"+"by".
  78.  *
  79.  *)
  80. function flex_midextend(anchor : flex_ptr;
  81.                 at, by : integer) : integer; extern;
  82.  
  83.  
  84. (* ---------------------------- flex_budge --------------------------------
  85.  * Description:    Function to move flex store, when the C library needs
  86.  *                 to extend the heap.
  87.  *
  88.  * Parameters:     int n -- number of bytes needed by C library
  89.  *                 void **a -- address of acquired store.  
  90.  * Returns:        amount of store acquired.
  91.  * Other Info:     Don't call this function directly, but register it 
  92.  *                 with the C library via:
  93.  *                    _kernel_register_slotextend(flex_budge);
  94.  *                 This will cause flex store to be moved up if the C
  95.  *                 library needs to extend the heap.  Note that in this 
  96.  *                 state, you can only rely on pointers into flex blocks 
  97.  *                 across function calls which do not extend the stack and 
  98.  *                 do not call malloc.
  99.  *                 The default state is flex_dont_budge, so, if required, 
  100.  *                 this function should be registered AFTER calling 
  101.  *                 flex_init().
  102.  *
  103.  *)
  104. function flex_budge(n : integer; a : flex_ptr) : integer; extern;
  105.  
  106.  
  107. (* -------------------------- flex_dont_budge -----------------------------
  108.  * Description:   Function to refuse to move flex store, when the C library 
  109.  *                needs to extend the heap.
  110.  *
  111.  * Parameters:    int n -- number of bytes needed by C library
  112.  *                void **a -- address of acquired store.
  113.  * Returns:       amount of store acquired (always 0).
  114.  * Other Info:    Don't call this function directly, but register it 
  115.  *                with the C library via:
  116.  *                   _kernel_register_slotextend(flex_dont_budge);
  117.  *                If the C library needs to extend the heap, flex will 
  118.  *                refuse to move. This means that you can rely on pointers 
  119.  *                into flex blocks across function calls.
  120.  *                This is the DEFAULT state after flex_init().
  121.  *
  122.  *)
  123. function flex_dont_budge(n : integer; a : flex_ptr) : integer; extern;
  124.  
  125.  
  126. (* ---------------------------- flex_init ---------------------------------
  127.  * Description:   Initialise store allocation module.
  128.  *
  129.  * Parameters:    void.
  130.  * Returns:       void.
  131.  * Other Info:    Must be called before any other functions in this module.
  132.  *
  133.  *)
  134. procedure flex_init; extern;
  135.  
  136. #endif
  137.  
  138. (* end flex.h *)
  139.